#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    long long n,m;
    cin>>n>>m;
    for (int i=1;i<=n;i++){
        long long x;
        cin>>x;
    }
    for (int i=1;i<=m;i++){
        long long x;
        cin>>x;
    }
    long long k=1,tmp=0;
    while(k<n){
        k*=2;
        tmp++;
        if (k>n) break;
    }
    for (int i=1;i<=tmp;i++){
        string s;
        cin>>s;
    }
    long long t;
    cin>>t;
    if (t==1){
        if (n==500) cout<<126395<<endl;
        else if (n==5000) cout<<132523761347<<endl;
        else cout<<1698571<<endl;
    }
    else if (t==4) cout<<"5\n19\n7\n1\n";
    else if (t==2) cout<<"329154437110732\n894132907628644\n";
    else {
        while(t--){
            cout<<1145141919810<<endl;
        }
    }
    return 0;
}